home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / moreisbetter / mib-libraries / moredevices / interruptsafedebug / generatefont / generatefont.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.4 KB  |  105 lines

  1. /*
  2.     File:        GenerateFont.c
  3.  
  4.     Contains:    Program to generate C source code for the InterruptSafeDebug font.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.          <1>    23/11/98    Quinn   First checked in.
  20. */
  21.  
  22. /////////////////////////////////////////////////////////////////////
  23.  
  24. // Setup MoreIsBetter environment
  25.  
  26. #include "MoreSetup.h"
  27.  
  28. // Mac OS interfaces
  29.  
  30. #include <MacTypes.h>
  31. #include <QDOffscreen.h>
  32. #include <Fonts.h>
  33.  
  34. // Standard C interfaces
  35.  
  36. #include <stdio.h>
  37.  
  38. /////////////////////////////////////////////////////////////////////
  39.  
  40. void main(void)
  41. {
  42.     OSStatus err;
  43.     GWorldPtr gWorld;
  44.     Rect bounds;
  45.     UInt8 *base;
  46.     ByteCount rowBytes;
  47.     ItemCount i;
  48.     ItemCount row;
  49.     
  50.     printf("Hello Cruel World!\n");
  51.     printf("QStandard.c\n");
  52.     fflush(stdout);
  53.  
  54.     // Create an offscreen GWorld to hold all 256 font
  55.     // characters, arranged horizontally.
  56.     
  57.     bounds.top = 0;
  58.     bounds.left = 0;
  59.     bounds.bottom = 10;
  60.     bounds.right = 256 * 8;
  61.     
  62.     err = NewGWorld(&gWorld, 1, &bounds, nil, nil, 0);
  63.     if (err == noErr) {
  64.         
  65.         // Setup the GWorld for our use.
  66.         
  67.         LockPixels(gWorld->portPixMap);
  68.         
  69.         SetGWorld(gWorld, nil);
  70.         TextFont(kFontIDMonaco);
  71.         TextSize(9);        
  72.         EraseRect(&bounds);
  73.         
  74.         // Draw all 256 characters, horizontally, into
  75.         // the offscreen GWorld.
  76.         
  77.         for (i = 0; i < 256; i++) {
  78.             MoveTo(i * 8 + 1, 7);
  79.             DrawChar(i);
  80.         }
  81.         
  82.         // Walk through the pixmap data in the GWorld,
  83.         // printing it to stdout.
  84.         
  85.         base = (UInt8 *) GetPixBaseAddr(gWorld->portPixMap);
  86.         rowBytes = ((**(gWorld->portPixMap)).rowBytes) & 0x3FFF;
  87.         for (row = 0; row < 10; row++) {
  88.             for (i = 0; i < 256; i++) {
  89.                 printf("0x%02x, ", *(base + (rowBytes * row) + i));
  90.             }
  91.             printf("\n");
  92.         }
  93.         
  94.         // Clean up.
  95.         
  96.         DisposeGWorld(gWorld);
  97.     }
  98.     
  99.     if (err == noErr) {
  100.         printf("Success!\n");
  101.     } else {
  102.         printf("Failed with error %ld.\n");
  103.     }
  104.     printf("Done.  Press command-Q to Quit.\n");
  105. }